package com.sany.taskmanager.room;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.sany.taskmanager.TaskManagerApplication;
import com.sany.taskmanager.room.dao.TaskDao;
import com.sany.taskmanager.room.entity.LocalTaskInfo;

@Database(entities = {LocalTaskInfo.class}, version = 1, exportSchema = false)
public abstract class TaskDatabase extends RoomDatabase {
    private static final String DB_NAME = "dbSanyBoomTask.db";
    private static volatile TaskDatabase mInstance;

    public static TaskDatabase getInstance() {
        if (mInstance == null) {
            synchronized (TaskDatabase.class) {
                if (mInstance == null) {
                    mInstance = Room
                            .databaseBuilder(TaskManagerApplication.getInstance(), TaskDatabase.class, DB_NAME)
                            .addMigrations()
                            .allowMainThreadQueries()
                            .build();
                }
            }
        }
        return mInstance;
    }

    public abstract TaskDao getTaskDao();

}
